package 多态;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GaoBo
 * Date: 2021-05-18
 * Time: 19:09
 */

class Shape {
    public void draw() {

    }
}

class Rect extends Shape{

    public void draw() {
        System.out.println("♦");
    }
}

class Cycle extends Shape{
    public void draw() {
        System.out.println("●");
    }
}

class Flower extends Shape{
    public void draw() {
        System.out.println("❀");
    }
}

class Triangle extends Shape{
    public void draw() {
        System.out.println("△");
    }
}

public class Test {

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void drawShapes1() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void drawShapes() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shape[] shapes = {cycle,rect,cycle,rect,flower};//向上转型
        //Shape shape = cycle;
        //Shape[] shapes2 = {new Cycle(),new Rect(),new Cycle(),new Rect(),new Flower()};//向上转型

        for (Shape shape : shapes) {
            shape.draw();
        }
    }





    public static void main(String[] args) {
        /*Shape shape = new Rect();
        shape.draw();
        Shape shape2 = new Cycle();
        shape2.draw();*/
        System.out.println("===============");
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle = new Triangle();
        drawMap(triangle);
        drawMap(rect);
        drawMap(cycle);

        //drawShapes();
    }
}
